Skip to content

feat: add Go cgo wrapper for Rust trace writer FFI#16

Closed
zah wants to merge 11 commits intowasm-tracingfrom
rust-trace-writer-ffi
Closed

feat: add Go cgo wrapper for Rust trace writer FFI#16
zah wants to merge 11 commits intowasm-tracingfrom
rust-trace-writer-ffi

Conversation

@zah
Copy link
Member

@zah zah commented Mar 10, 2026

Summary

  • Create tracewriter/ package with TraceRecorder interface abstracting over Go and Rust trace writers
  • GoWriter wraps existing trace_record.TraceRecord (default, no behavior change)
  • RustTraceWriter wraps C FFI via cgo (opt-in with --use-rust-writer flag)
  • Change ModuleInstance.Record from concrete *trace_record.TraceRecord to TraceRecorder interface
  • Update all call sites: store.go, runtime.go, stylus.go, stylus_funcs.go
  • Update wazero.nix to conditionally enable cgo when FFI library is provided
  • Adapt to trace_record Address uint64 change (cast to uint32 for WASM32 memory reads)
  • Forward metadata, return values, and workdir through FFI in ProduceTrace

Dependencies

Test plan

  • CGO_ENABLED=0 go build ./... passes (full project without cgo)
  • CGO_ENABLED=0 go test ./tracewriter/ -v — 5/5 GoWriter tests pass
  • go vet reports no new warnings
  • Existing Go trace writer path is fully preserved as default
  • With FFI library linked: CGO_ENABLED=1 go test ./tracewriter/ -v (requires nix build of trace-writer-ffi)

🤖 Generated with Claude Code

zah and others added 11 commits March 10, 2026 09:49
- Create tracewriter/ package with TraceRecorder interface
- GoWriter wraps existing trace_record.TraceRecord (default)
- RustTraceWriter wraps C FFI via cgo (opt-in with --use-rust-writer)
- Buffer events during recording, replay through FFI in ProduceTrace()
- Change ModuleInstance.Record to TraceRecorder interface
- Update all call sites: store.go, runtime.go, stylus.go, stylus_funcs.go
- Update wazero.nix to conditionally enable cgo with FFI library
- GoWriter tests pass, full project compiles with CGO_ENABLED=0

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Cast uint64 Address to uint32 for WASM32 memory reads
- Add go.mod replace directive for local trace_record development

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Forward metadata in register_special_event (EVM hook names preserved)
- Forward return values via register_return_int/raw dispatch
- Forward workdir to trace_writer_set_workdir in ProduceTrace
- Update local C header copy with new function declarations

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add a GitHub Actions workflow that clones CodeTracer and trace_record,
builds wazero from this PR, and runs the WASM flow integration test.
This catches recorder changes that would produce incompatible traces.

Follows the cross-repo testing pattern documented in codetracer-specs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fail fast with a clear error message if the secret is missing,
rather than failing cryptically during submodule clone.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…guard

- Add justfile with test, build, test-tracewriter, and check targets
- Add tracewriter job to commit.yaml for pure Go tracewriter tests
- Pin sibling codetracer ref to latest-trace-format branch
- Add --test wasm_flow_integration flag + zero-test guard to integration workflow

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The PR targets wasm-tracing, not main. Add wasm-tracing to the
pull_request and push branch filters so the Test workflow runs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove stale dirs before clone (self-hosted runners persist)
- Add sibling-pins debug output to diagnose ref resolution
- Remove 2>/dev/null from python to surface errors

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Self-hosted NixOS runners don't have python3 on PATH. Use grep+sed
to extract JSON values instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…l triggers

The existing wazero tests in commit.yaml fail on wasm-tracing branch
because go.mod has a replace directive for ../trace_record which doesn't
exist in standard CI checkout.

Move tracewriter tests to a dedicated workflow that clones trace_record
at the pinned ref before running tests. Revert commit.yaml triggers
back to main-only.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The tracewriter package includes rust_writer.go with cgo, which
requires libcodetracer_trace_writer_ffi. Set CGO_ENABLED=0 for
test-tracewriter target to exclude the Rust FFI code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@zah
Copy link
Member Author

zah commented Mar 10, 2026

Merged manually

@zah zah closed this Mar 10, 2026
@zah zah deleted the rust-trace-writer-ffi branch March 10, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant